package net.xuzhen97.distributed.transaction.course.dao;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * UserCourse仓储类，主要是mybatis plus的一些加强方法
 * @author xuzhen97
 */
@Repository
public class UserCourseRepository extends ServiceImpl<UserCourseMapper, UserCourse> {

    /**
     * 根据用户id和课程id获取关联关系
     * @param userId
     * @param courseId
     * @return
     */
    public UserCourse getByUserIdAndCourseId(String userId, String courseId){
        UserCourse userCourse = getOne(Wrappers.<UserCourse>lambdaQuery()
                .eq(UserCourse::getUserId, userId)
                .eq(UserCourse::getCourseId, courseId));
        return userCourse;
    }
}
